<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>候选人查看列表</title> 
</head>
<body>
<div class="ui segment" id="n-page">
&nbsp;<br>
    <div class="list-row">
        <div class="list-title-1-1">
            姓名
        </div>
        <div class="list-title-1-2">
            现任公司
        </div>
        <div class="list-title-1-3">
           应聘职位
        </div>
    </div>
    <div id="row-data">
    <c:forEach items="${recomlist}" var="rp">
        <div class="position" data-position-id="${rp.id}">
            <div class="list-row">
                <div class="list-position-1-1">
                ${rp.name}
                </div>
                <div class="list-position-1-2">
                ${rp.companyname}
                </div>
                <div class="list-position-1-3">
                ${rp.positionname}
                </div> 
            </div>
            <div class="list-row">
                <div class="list-position-2-1">
                  ${rp.location }
                </div>
               <%--  <div class="list-position-2-2">
                  ${rp.positionname}
                </div> --%>
                 <div class="list-position-2-2">
                <c:choose>
	                <c:when test="${rp.status == 0 }">
	                    等待邀请
	                </c:when>
	                <c:when test="${rp.status == 1 }">
	                    推荐中
	                </c:when>
	                <c:when test="${rp.status == 2 }">
	                    推荐成功
	                </c:when>
	                <c:otherwise>
	                    推荐失败
	                </c:otherwise>
            	</c:choose>
                </div>
            </div>  
        </div>
    </c:forEach>
    </div>

</div>

<!-- 测试用，正式发布关闭 
<div id="testid">
点击获取更多数据
</div>
-->
<input type="hidden" name="lastposition" id="lastjob" value="${fn:length(recomlist)}"/>
<input type="hidden" name="hasmoredata" id="hasmoredata" value="yes"/> 

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'showOptionMenu']  
});
	
    var datasource = { 
        moredata: function() { 
            var getUrl = '${ctx}/wechat/hunter/morejobcandidate.do';
            var offset  = $('#lastjob').val();
            var hasmore = $('#hasmoredata').val();

            getUrl += "?offset=" + offset;

            if(hasmore != "yes"){
                console.log("已经没有更多数据了");
                return false;
            }
            var that = this;

            $.ajax({ 
                    url: getUrl, 
                    type: "GET", 
                    success: function(data, status){ 
                        if(data.errorcode == 0) {
                            that.appenddata(data);
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            location.href = errorUrl;
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                    } 
            });
        },

        appenddata:function(data) { 
            var offset = parseInt($('#lastjob').val());
            var divstring = "";
            var recomlist = data.data;

            var count = recomlist.length;
            offset += parseInt(count);
            $('#lastjob').val(offset);
            if(count <10) {
                $('#hasmoredata').val('no');
            }

            for (var i in recomlist) {
                var rp = recomlist[i];

                divstring += "<div class='position' data-position-id='"+ rp.id +"'>";
                divstring += " <div class='list-row'>";
                divstring += "  <div class='list-position-1-1'>";
                divstring += rp.name;
                divstring += "  </div>";
                divstring += "  <div class='list-position-1-2'>";
                divstring += rp.companyname;
                divstring += "  </div>";
                divstring += "  <div class='list-position-1-3'>";
                divstring += rp.positionname;
                divstring += "  </div>";
                divstring += " </div>";
                divstring += "</div>";
                divstring += "<div class='list-row'>";
                divstring += "<div class='list-position-2-1'>";
                divstring += rp.location;
                divstring += "</div>";
                divstring += "<div class='list-position-2-2'>";
                divstring += rp.positionname;
                divstring += "</div>";
                divstring += "</div>";
            }

            var newdata = $(divstring);
            $('#row-data').append(newdata);
        }
    };

    $(document).ready(function() { 
       
    	var l = sessionStorage.getItem('index_list');
    	 
    	if(null !== l && '' !== l){
    	    $("#row-data").html(l);
    	    $(window).scrollTop(sessionStorage.getItem('index_scroll'));
    	    page = sessionStorage.getItem('index_page');
    	    sessionStorage.removeItem('index_list');
    	    sessionStorage.removeItem('index_scroll');
    	}else{
    		datasource.moredata();
    	};
    	
    	
	   	 $(window).scroll(function() { 
	         if($(window).scrollTop() == $(document).height() - $(window).height()) {
	             datasource.moredata();
	         } 
	   	 });
        
         $('#row-data').on('click','.position', function() {
        	 var offset  = $('#lastjob').val();
             var positionid = $(this).attr('data-position-id');
             var getUrl = '${ctx}/wechat/hunter/toInterview.do?recommendid='+positionid;
             sessionStorage.setItem('index_list',$("#row-data").html());
             sessionStorage.setItem('index_page',offset);
             sessionStorage.setItem('index_scroll',$(window).scrollTop());
             window.location.href = getUrl;
         });

         wx.ready(function() {
          wx.onMenuShareAppMessage({
              title: 'Headoffer--专业招聘平台----推荐有奖！',  
              desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',  
              link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',  
              imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',  
              type: 'link'
          });

          wx.onMenuShareTimeline({
              title: 'Headoffer--专业招聘平台----推荐有奖！',  
              desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',  
              link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',  
              imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
          });

          wx.showOptionMenu();
            
           
        });
                 
    });

</script>
</body>
</html>